import { alovaInstance } from '..'
import type { UserIn, UserListOut, UserPwdIn } from '../globals'

// 返回 一个对象或空对象{}
type EmptyBody = Record<PropertyKey, never>
interface UserRowsType {
  name: string
  addr: string
  qq: string
}

// 用户列表
export interface userList {
  name: string
  gender: string
  age: number
  addr: string
  status: boolean
}

// 获取用户信息
export const getUserInfo = (id: string) => alovaInstance.Get<UserRowsType[]>('/user' + id)

// 新增用户
export const addUser = (data: UserIn) =>
  alovaInstance.Post<UserListOut>('system_manage/user/add_user', data)

// 删除一个用户
export const deleteUser = (id: number | string) =>
  alovaInstance.Delete<EmptyBody>('system_manage/user/delete_user/' + id)

// 批量删除用户
export const deleteBatchUser = (ids: number[] | string[]) =>
  alovaInstance.Post<EmptyBody>('system_manage/user/delete_batch_user/', ids)

// 更新用户
export const updateUser = (id: number | string, data: UserIn) =>
  alovaInstance.Put<UserListOut | EmptyBody>('system_manage/user/update_user/' + id, data)

// 重置/设置用户密码
export const updateUserPwd = (id: number | string, data: UserPwdIn) =>
  alovaInstance.Put<UserListOut | EmptyBody>('system_manage/user/update_user_password/' + id, data)

// 获取用户列表
export const getUserList = () =>
  alovaInstance.Get<UserListOut[]>('system_manage/user/get_user_list')

// 获取一个用户
export const getUser = (id: number | string) =>
  alovaInstance.Get<UserListOut | EmptyBody>('system_manage/user/get_user/' + id)
